import Vue from 'vue'
import Vuex, { Commit, Dispatch } from 'vuex'
import actions from './actions'
import getters from './getters'
import cart, { State as CartState } from './modules/cart'
import products, { State as ProductState } from './modules/products'

Vue.use(Vuex);

export default new Vuex.Store({
  actions,
  getters,
  modules: {
    cart,
    products
  }
})
// 全局的state, 所以获取或修改这些时，需要到全局的getters、actions
export interface State {
  cart: CartState,
  products: ProductState
}
// 定义全局的context, 个人建议可以不用定义，用的时候直接声明对象即可
export interface ActionContextBasic {
  commit: Commit,
  dispatch: Dispatch
}

// 定义商品列表接口
export interface Product {
  id: number,
  title: string,
  price: number,
  inventory: number
}

// 定义购物车商品接口
export interface CartProduct {
  title: string,
  price: number,
  quantity: number
}

// 加入购物车接口
export interface AddToCartPayload {
  id: number
}

// 结算结果类型
export type CheckoutStatus = 'successful' | 'failed' | null
